<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<%@ page import="com.scalar.chiptrack.operations.dataentry.forms.InventoryDataEntryForm,
                 com.scalar.chiptrack.utils.ConfigManager,
				 com.scalar.chiptrack.users.Functionality,
				 com.scalar.chiptrack.commons.Constants"%>

<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/chiptrack-tags.tld" prefix="chiptrack" %>
<chiptrack:checkLogon sourcePage="/inventoryDataEntry.do"/>

<%String chipTracContext = "/" + ConfigManager.getChipTracContext();%>

<script src="<%=chipTracContext%>/jsp/includes/scripts/functions.js"></script>



<HTML><HEAD>
<script>


	function validateProductAndLoc(){
		var processStepId = document.inventoryDataEntry.processStepId.value;
		var locationId = document.inventoryDataEntry.locationId.value;
		var msg="";
		if ((processStepId==0) &&(locationId ==0)){
			msg="ProductName and Location";
			return msg;
		}
		else if ((processStepId==0) ||(locationId ==0)){
			if (processStepId==0){
				msg=" ProductName";
				return msg;
			}
			else{
				msg=" Location";;
				return msg;
			}
		}
		else
			return true;
	}

	function validateLotNo(){
			var lotMsg="";
			var newLotNo= document.inventoryDataEntry.newLotNo.value;
			if(newLotNo=='' || newLotNo==null){
				lotMsg=" Lot Number";
				return lotMsg;
			}
			else
				return true;

	}

	function validateDate(){
		var dateIn	= document.inventoryDataEntry.dateIn.value;
		var dateMsg="";
			if(dateIn==''|| dateIn==null){
				dateMsg="Date In";	
				return dateMsg;
			}
			
			else if(dateIn!=''){
				if (!validateDateOnly(dateIn)){	
					dateMsg=" Valid date";
					return dateMsg;
				}
				return true;
			}
						
	}

	function validateQuantity(){
				var quantityIn		= document.inventoryDataEntry.quantityIn.value;
				var qtyMsg="";
				if(quantityIn=='' || quantityIn==null){
					qtyMsg="Quantity In";
					return qtyMsg;
				}
				
				if(quantityIn!=''){
					if (!isInteger(quantityIn)){	
						qtyMsg=" Quantity In";	
						return qtyMsg;
					}
				}
				
				if ( (quantityIn!='') && isInteger(quantityIn) )
					return true;
	}

function inventoryDataEntry()
{
	var quantityIn		= document.inventoryDataEntry.quantityIn.value;
	var quantityOut		= document.inventoryDataEntry.quantityOut.value;
	var dateIn			= document.inventoryDataEntry.dateIn.value;
	var dateOut			= document.inventoryDataEntry.dateOut.value;
	var pa				= document.getElementById("message");
	var lotNo		    = document.inventoryDataEntry.newLotNo.value;
	var finalMsg = "<li>Please Choose a valid ";
	
	if(validateProductAndLoc()!=true)
		finalMsg = finalMsg+validateProductAndLoc();
	if ( validateLotNo()!=true || validateQuantity()!=true){
		//alert("This is loop check == false");
		if ( validateLotNo()!=true && validateQuantity()!=true ){
				if(validateDate()!=true){
					pa.innerHTML = finalMsg+validateLotNo()+", "+validateDate()+" and "+validateQuantity();	 
					return;
				}
				else{
					pa.innerHTML = finalMsg+validateLotNo()+" and "+validateQuantity();	 
					return;				
				}

		}
		
		else if(validateLotNo()==true ){
			if (validateDate()!=true){
				pa.innerHTML = finalMsg+validateDate()+" and "+validateQuantity();			
				return;
			}
			else{
				pa.innerHTML = finalMsg+validateQuantity();			
				return;
			}

		}
		else{
			if (validateDate()!=true){
				pa.innerHTML = finalMsg+validateDate()+" and "+validateLotNo();			
				return;
			}
			else{
				pa.innerHTML = finalMsg+validateLotNo();	
				return;
			}
		}

	}
	else if(validateProductAndLoc()!=true){
		//finalMsg = "Please select a " + validateProductAndLoc();
		//alert (finalMsg);
		pa.innerHTML = finalMsg ;
		return;
	}
			
	else{
		//alert("This is loop check == true");
		var outQty = document.inventoryDataEntry.quantityOut.value;
		var outDate= document.inventoryDataEntry.dateOut.value;
		
		var msg="";

		if (outQty !='' || outQty!=null){
			if(!isInteger(outQty)){
				msg=" Quantity Out";
			}			
		}
		
		if (outDate !=''){
			if (!validateDateOnly(outDate)){	
				msg=msg+" "+" Date Out";
			}
		}

		
		if (msg==""){
			var exists = <%=(String) request.getAttribute("Exists")%>;
			document.inventoryDataEntry.action="<%=chipTracContext%>/inventoryDataEntry.do?action=save&Exists="+exists;
			document.inventoryDataEntry.submit();
		}
		else{
			pa.innerHTML=finalMsg+msg;
			return;
		}
	}

}

</script>
<TITLE>Scalarsoft - ChipTrac</TITLE>
<META http-equiv=Content-Type content="text/html; charset=windows-1252">
<LINK href="<%=chipTracContext%>/jsp/includes/stylesheets/scalarsoft.css" type=text/css rel=stylesheet>

<META content="Microsoft FrontPage 5.0" name=GENERATOR></HEAD>
<BODY bgColor=#ffffff leftMargin=0 topMargin=0 marginheight="0" marginwidth="0">

<html:form name="inventoryDataEntry"  type="com.scalar.chiptrack.operations.dataentry.forms.InventoryDataEntryForm" action="/inventoryDataEntry">

<!-- Top Header Start-->
<%@ include file="/jsp/includes/header.jsp" %>
<!-- Top Header End-->

<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
  <TBODY>
  <TR>
	<td width='180' valign='top' background='<%=chipTracContext%>/jsp/includes/images/left_red_bg.gif'>

<!-- Side Navigation start -->
<%@ include file="/jsp/operations/dataentryMenu.jsp" %>
<!-- end of the side navigations -->
<TD bgcolor="#ffffff">
<IMG height=9 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=8></TD>

<TD bgcolor="#ffffff"><IMG height=480 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=2></TD>

<TD valign="top" width="100%">
<IMG height=1 src="<%=chipTracContext%>/jsp/includes/images/clear.gif" width=500 border=0>
<BR>
<!-- from here your body starts -->


<center><span class="NArialW">Inventory Data Entry</span></center>
<p>&nbsp;
<center>
<!--
<strong><font face="Verdana" size="-5" align="center" color="#ff0000" id="message"></font>
-->
</center>

<% String message = (String)request.getAttribute("ErrMsg");
   if(message==null)
   message=""; 
   
   String action = (String)request.getParameter("action");
   if(action==null)
   action = " no action";
	
	String exists =(String)request.getAttribute("Exists");
	//System.out.println("action in Jsp "+action)	;

	if(request.getAttribute("inventorydataentryform")==null)
	{
		InventoryDataEntryForm invDataEntryForm = new InventoryDataEntryForm();
		request.setAttribute("inventorydataentryform",invDataEntryForm);
	}

 %>

<% if(!message.equals("")){%>	
	<p align ="center">
	 <strong><font face="Verdana" size="-5" align="center" color="#ff0000"><b><%=message%></b></font>
    </p>
<% }  %><img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=20>
<font class="NArialL">

</p>

<table border="0" width="90%" align=right>
  <% if ( !user.isActionAllowed ( Functionality.DATA_ENTRY, User.USER_ACTION_MODIFY  )  ) { %> 
  <tr><td colspan='5'> 
  <font class='NArialS'><font color='blue'><b><%=Constants.NO_MODIFY_RIGHTS %></b>
  </font></td></tr>  
  <% } %>
  <tr><td colspan='5'><strong><font face="Verdana" size="-5" align="center" color="#ff0000" id="message"></font></td></tr>
  <tr><td colspan='5'><chiptrack:errors styleClass='NArialL'/></td></tr>
  <tr><td colspan='5'><chiptrack:info styleClass='NArialL'/></td></tr>
  <% if ((exists != null) && (exists.equalsIgnoreCase("true"))){ %>
  <tr><td colspan='5'>  <a href="javascript:inventoryDataEntry();"><img border="0" 					
						src="<%=chipTracContext%>/jsp/includes/images/confirm.gif" width="75" height="17"></a>
						&nbsp;&nbsp;&nbsp;&nbsp;
						<a href="#" onclick = "javascript:window.history.back();" ><img border="0" src="<%=chipTracContext%>/jsp/includes/images/back.gif" width="40" height="17"></a>
  </td></tr>
  <%}%>
  <tr><td colspan='5'><img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=10></td></tr>
  
   <%if(action.equals("partnumber") || action.equals("save") || action.equals("submit")  ) {%> 
 
  <tr>
    <td width="20%"><font class="NArialL">Part Number : <font color=red>*</font><br> (<bean:message key = "label.mfgPartNumber" />)</font></td>
    <td width="25%">
	<p><font class="NArialL">
	<html:select property="processStepId"  name="inventorydataentryform" styleClass="txfield" >
	<html:option value="0">Select Part Number</html:option> :<html:options collection="partNumberSelectList" property="value" labelProperty="label"/></html:select></font></p>
	</td>
    <td width="7%">&nbsp;</td>
  </tr>
  <% }%>
     <%if(action.equals("partnumber")|| action.equals("save") || action.equals("submit") ){%>
  <tr>
	<td width="20%"><font class="NArialL">Location :<font color=red> *</font></font></td>
    <td width="25%">
	<p><font class="NArialL">
	<html:select property="locationId"  name="inventorydataentryform" styleClass="txfield" >
	<html:option value="0">Select Location</html:option>
    <html:options collection="locationSelectList" property="value"
                   labelProperty="label"/>
    :</html:select></font></p>
	
	</td>
  
   <tr>
   <%}%>
			<tr>
							<td width="20%">&nbsp;</td>
							<td width="20%">&nbsp;</td>
							<td width="20%">&nbsp;</td>
			</tr>

  
		 <%if(action.equals("partnumber") || action.equals("save") || action.equals("submit")  ) {%> 
				<tr>
				<td width="20%"><font class="NArialL">New Lot Number : <font color=red>*</font></font></td>
				<td width="25%">
				<html:text  name="inventorydataentryform" property="newLotNo" size="16" styleClass="txfield" maxlength='50'/>
				</td>
				<td width="20%"><font class="NArialL">Date Code :</font></td>
				<td width="25%">
				<html:text  name="inventorydataentryform" property="dateCode" size="16" styleClass="txfield" />
				</td>
			  </tr>
			  
				<tr>
				<% String dateIn = (String)request.getAttribute("DateIn");%>
				<td width="20%"><font class="NArialL">Date In : <font color=red>*</font></font></td>
				<td width="25%"><font class="NArialL">
				<html:text  name="inventorydataentryform" property="dateIn" value = "<%= dateIn%>" size="16" styleClass="txfield" maxlength='10' />

				</font>


				</td>
				<td width="20%"><font class="NArialL">Date Out :</font></td>
				<td width="20%"><font class="NArialL">
				<html:text  name="inventorydataentryform" property="dateOut" size="16" styleClass="txfield" maxlength='10' />

				</font>


				</td>
				<td width="7%"></td>
			  </tr>
			  			  
			  <tr>
				<td width="20%"><font class="NArialL">Quantity In : <font color=red>*</font></font></td>
				<td width="25%">
				<html:text  name="inventorydataentryform" property="quantityIn" size="16" styleClass="txfield" maxlength='4' />
				</td>
				<td width="20%"><font class="NArialL">Quantity Out :</font></td>
				<td width="20%">
				<html:text  name="inventorydataentryform" property="quantityOut" size="16" styleClass="txfield" maxlength='4' />
				</td>
				<td width="7%">&nbsp;</td>
			  </tr>
			  
			  <tr>
				<td width="20%"></td>
				<td width="25%"></td>
				<td width="20%"></td>
				<td width="20%">


				</td>
				<td width="7%">&nbsp;</td>
			  </tr>
			    <tr><td colspan=5><img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=20></td></tr>
				<tr><td colspan=4 align=center>
				<!--Bhaskar commented the normal href link below and added restricted link on 10 oct 2003-->
				<!--a href="javascript:inventoryDataEntry();"><img border="0" src="< %=chipTracContext%>/jsp/includes/images/save.gif" width="53" height="17"></a-->
				<chiptrack:restrictedLink functionality='<%=Functionality.DATA_ENTRY%>' action='<%=User.USER_ACTION_MODIFY%>' href='javascript:inventoryDataEntry();' onmouseover="window.status='Click here to save inventory details';return true" onmouseout="window.status='';return true">
				<img border="0" src="<%=chipTracContext%>/jsp/includes/images/save.gif" width="53" height="17"></chiptrack:restrictedLink> 
				  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
				<a href="<%=chipTracContext%>/inventoryDataEntry.do?action=partnumber" ><img border="0" src="<%=chipTracContext%>/jsp/includes/images/cancel.gif" width="53" height="17"></a>
			  </td></tr>
		  	  <%}%>
				  		
</table>




<!-- till here -->
<BR><BR><BR></TD>
<TD bgcolor="#ffffff"><IMG height=1 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=1></TD>
</TR>
</TABLE>
<!-- Footer starts here -->
<%@ include file="/jsp/includes/footer.jsp" %>
<!-- footer end here -->
</html:form>
</BODY>
</HTML>